Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp.dest uses chmod on files #1012

Closed
hashworks opened this issue Apr 10, 2015 · 12 comments
Closed

gulp.dest uses chmod on files #1012

hashworks opened this issue Apr 10, 2015 · 12 comments

Comments

@hashworks
Copy link

When I pipe my compiled css into gulp.dest(folder) it will fail with an error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: EPERM, chmod 'css/screen.css'

This is because screen.css already exits and only gets overriden - however the user running gulp isn't the owner of the file.

This is a bug since according to the documentation chmod gets applied to new folders only:
options.mode - Octal permission string specifying mode for any folders that need to be created for output folder.

Code:

var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('default', function() {
    gulp.src(sassUri + '**/*.{scss,sass}')
        .pipe(sass())
        .pipe(gulp.dest('css'));
});

PS: If this isn't a bug but a feature, how can I turn this off (or handle it properly)?

@stephenlacy
Copy link
Contributor

What OS are you using?
A user can not modify a file with another user's permission. Only an admin, or user in the same group, would be able to modify that file.
To mitigate this issue first change the permission of the original file to the user running gulp. Or add the gulp user to that folder/file.

The options.mode only affects "folders that need to be created" not existing folders with another user's permissions.

@hashworks
Copy link
Author

Yeah, I understand how chmod works on GNU/Linux. But on my systems gulp can and will by run by many different users (which are in the same group, though). IMO gulp has absolutely no need to run chmod on this file, since he only needs to write to it.

If I'm unable to turn of this feature I'm absolute ok with catching and ignoring it - my only intention is that the watcher doesn't fail because of this. Could you show me an example how to catch this error?

@yocontra
Copy link
Member

@hashworks this shouldn't be a problem. can you go here in vinyl-fs (in your local node_modules folder) and add some logging and let me know what these vars are?

https://github.com/wearefractal/vinyl-fs/blob/96867b4687d3a4c09cdd4db9a49134a87543b683/lib/dest/writeContents/index.js#L48

@hashworks
Copy link
Author

My node_modules/gulp/node_modules/vinyl-fs/lib/dest/writeContents/index.js is different: http://pastebin.com/zr76Kt6q

However I added this before line 27:

console.log(currentMode);
console.log(file.stat.mode);

Which results in:

436
33188
[16:03:54] 'sass' errored after 15 ms
[16:03:54] Error: EPERM, chmod 'foobar.css'

@yocontra
Copy link
Member

It's different? Can you run npm ls vinyl-fs ?

@hashworks
Copy link
Author

└─┬ gulp@3.8.11
└─ vinyl-fs@0.3.13

Just as the package.json of gulp says - ^0.3.0.

@yocontra
Copy link
Member

Can you try this with gulp 4? AFAIK this should be totally fixed

@hashworks
Copy link
Author

Seems like the 4.0 build is broken:
`npm install --save-dev git://github.com/#4.0'

var gulp = require('gulp');

gulp.task('default', function() {
    return gulp.src('./screen.css')
        .pipe(gulp.dest('./'));
});
/usr/local/lib/node_modules/gulp/bin/gulp.js:129
    gulpInst.start.apply(gulpInst, toRun);
                   ^
TypeError: Cannot call method 'apply' of undefined
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickDomainCallback (node.js:463:13)

This happens as well when I call a gulpfile.js that only includes var gulp = require('gulp');.

@phated
Copy link
Member

phated commented Apr 14, 2015

@hashworks you need to be using the version of the CLI globally installed from gulpjs/gulp-cli#4.0

@hashworks
Copy link
Author

Ah, that was obvious.

It works with 4.0, no chmod error. I'll wait for a release then. Thanks 👍

@yocontra
Copy link
Member

@hashworks There was a bug with the chmod stuff in 3.x - feel free to use the 4.0 stuff it's stable, just waiting on a few more issues to land before we publish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@yocontra @phated @hashworks @stephenlacy and others